package com.yxw.yxnet_cd_center.common.helper;


import com.yxw.yxnet_cd_center.common.enums.CommonErrorEnum;
import com.yxw.yxnet_cd_center.common.exception.BaseException;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;

/**
 * @desc:
 * @program: 分页封装返回
 * @author: liuxin
 * @date: 2023.09.13
 */
public class ResultHelper {

    public ResultHelper() {
    }

    /**
     * 成功
     *
     * @param <T>
     * @param data
     */
    public static <T> BaseResult<T> fillWithSuccess(T data) {
        BaseResult<T> result = new BaseResult<>();
        result.setResult(true);
        result.setResultCode("200");
        result.setData(data);
        result.setResultMsg("查询成功");
        return result;
    }

    /**
     * 失败
     *
     * @param err
     */
    public static <T> BaseResult<T> fillWithFailure(CommonErrorEnum err) {
        BaseResult<T> result = new BaseResult<>();
        result.setResult(false);
        result.setResultCode(err.getCode());
        result.setResultMsg(err.getDescription());
        return result;
    }
}

